import Vue from 'vue'
import Router from 'vue-router'
// import Home from './components/Home.vue'
// import User from './components/user/Users.vue'
// import Welcome from './components/Welcome.vue'
// import Rights from './components/power/Rights.vue'
// import Roles from './components/power/Roles.vue'
// import Categories from './components/goods_cate/Categories.vue'
// import Params from './components/goods_params/Params.vue'
// import Goods from './components/goods/Goods.vue'
// import Goodsadd from './components/goods/Goodsadd.vue'
// import Orders from './components/orders/Orders.vue'
// import Reports from './components/reports/Reports.vue'
// import Login from './components/Login.vue'
const Login = () =>
    import(/* webpackChunkName:"login_home_welcome" */ './components/Login.vue')

const Home = () =>
    import(/* webpackChunkName:"login_home_welcome" */ './components/Login.vue')

const Welcome = () =>
    import(/* webpackChunkName:"login_home_welcome" */ './components/Login.vue')

const User = () =>
    import(/* webpackChunkName:"user" */ './components/user/Users.vue')

const Rights = () =>
    import(/* webpackChunkName:"power" */ './components/power/Rights.vue')

const Roles = () =>
    import(/* webpackChunkName:"power" */ './components/power/Roles.vue')

const Categories = () =>
    import(/* webpackChunkName:"goods" */ './components/goods_cate/Categories.vue')

const Params = () =>
    import(/* webpackChunkName:"goods" */ './components/goods_params/Params.vue')

const Goods = () =>
    import(/* webpackChunkName:"goods" */ './components/goods/Goods.vue')

const Goodsadd = () =>
    import(/* webpackChunkName:"goods" */ './components/goods/Goodsadd.vue')

const Orders = () =>
    import(/* webpackChunkName:"orders" */ './components/orders/Orders.vue')

const Reports = () =>
    import(/* webpackChunkName:"orders" */ './components/reports/Reports.vue')
Vue.use(Router)

const router = new Router({
  routes: [{
    path: '/',
    redirect: '/home'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [{
      path: '/welcome',
      component: Welcome
    },
    {
      path: '/users',
      component: User
    },
    {
      path: '/rights',
      component: Rights
    },
    {
      path: '/roles',
      component: Roles
    },
    {
      path: '/categories',
      component: Categories
    },
    {
      path: '/params',
      component: Params
    },
    {
      path: '/goods',
      component: Goods
    },
    {
      path: '/goods/add',
      component: Goodsadd
    },
    {
      path: '/orders',
      component: Orders
    },
    {
      path: '/reports',
      component: Reports
    }
    ]
  }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) {
    return next('/login')
  }
  next()
})

export default router
